package cate.game.role.pvp.teampvp.msg;

import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBTeamPvp;
import cate.game.pvp.teampvp.dto.TeamPvpMatchData;

@ClientMsg(title = "匹配请求")
public class TeamPvpMatchReq implements MsgInput {

    @Override
    public void execute(GameBody game, ClientContext cc) {
        int rank = game.rank.getPointRaceAdapter().getRoleRank(game, cc.getRole().getUid());
        if (rank < 0 || rank >= 100) {
            game.notice.message(cc.getRole(), "竞技场前100名才可参与");
            return;
        }
        GameResult<TeamPvpMatchData> matchRes = game.pvp.teamPvp.match(cc.getRole());
        if (!matchRes.ok()) {
            game.notice.message(cc.getRole(), matchRes);
            return;
        }
        if (matchRes.data == null) {
            game.notice.message(cc.getRole(), "匹配失败拉，请重新尝试");
            return;
        }
        cc.sendNow(new TeamPvpMatchResp(matchRes.data));
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBTeamPvp.MATCH_REQ;
    }
}
